package com.by.receiver;


import cn.hutool.json.JSONUtil;
import com.by.config.Constant;
import com.by.entity.Order;
import com.by.mapper.OrderMapper;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.channels.Channel;

@Component
public class OrderReceiver {

    @Autowired
    private OrderMapper orderMapper;

    @RabbitListener(queues = {Constant.ORDER_QUEUE})
    public void receive(String msg, Channel channel) {
        Order order = JSONUtil.toBean(msg, Order.class);
        orderMapper.insert(order);
    }
}
